@model LanLordz.Models.DoorPrizesModel
@{
    ViewBag.Title = "Door Prizes";
}
@section headers
{
  <script type="text/javascript" language="javascript">
      //<![CDATA[
      function Draw(prizeId) {
          $('#Action').val('DRW');
          $('#Value').val(prizeId);
          $('#Value').parents('form:first').submit();
      }

      function Add(prizeName) {
          $('#Action').val('ADD');
          $('#Value').val(prizeName);
          $('#Value').parents('form:first').submit();
      }

      function Revoke(prizeId) {
          $('#Action').val('RVK');
          $('#Value').val(prizeId);
          $('#Value').parents('form:first').submit();
      }

      function Delete(prizeId) {
          $('#Action').val('DEL');
          $('#Value').val(prizeId);
          $('#Value').parents('form:first').submit();
      }
      //]]>
  </script>
}
    <h2>@ViewBag.Title</h2>
    @using (Html.BeginForm())
    {
     @Html.AntiForgeryToken()
     @Html.Hidden("Action")
     @Html.Hidden("Value")
     <p>Door Prizes:</p>
     <table>
      @foreach (var prize in Model.Prizes)
      {
      <tr>
       <td>@prize.Name</td><td>@(prize.WinnerUserId.HasValue ? prize.User.Username : "(unassigned)")</td>
       <td>
       @if (prize.WinnerUserId == null)
       {
        <button onclick="Draw(@prize.PrizeId)">Draw</button>
        <button onclick="Delete(@prize.PrizeId)">Delete</button>
       }
       else
       {
        <button onclick="Revoke(@prize.PrizeId)">Revoke</button>
       }
       </td>
      </tr>
      }
     </table>
    }
  <div>
     @Html.TextBox("NewPrizeName") <button onclick="Add($('#NewPrizeName').val())">Add Prize</button>
  </div>
